﻿package pages.application {
	import flash.events.MouseEvent;
	import flash.display.MovieClip;

	import events.NBEvent;

	/**
	 * @author Hank
	 * 2009-9-29
	 */
	public class Application extends MovieClip {
		public var forwardBtn : MovieClip;
		public var backwardBtn : MovieClip;

		public function Application() {
			creat();
		}

		public function lock() : void {
			if(forwardBtn) {
				forwardBtn.buttonMode = false;
				forwardBtn.removeEventListener(MouseEvent.CLICK, onClickHanlder);
			}
			
			if(backwardBtn) {
				backwardBtn.buttonMode = false;
				backwardBtn.removeEventListener(MouseEvent.CLICK, onClickHanlder);
			}
		}

		public function unlock() : void {
			if(forwardBtn) {
				forwardBtn.buttonMode = true;
				forwardBtn.addEventListener(MouseEvent.CLICK, onClickHanlder);
			}
			
			if(backwardBtn) {
				backwardBtn.buttonMode = true;
				backwardBtn.addEventListener(MouseEvent.CLICK, onClickHanlder);
			}
		}

		private function creat() : void {
			forwardBtn = this.getChildByName("forwardBtn") as MovieClip;
			backwardBtn = this.getChildByName("backwardBtn") as MovieClip;
			unlock();
		}

		private function onClickHanlder(e : MouseEvent) : void {
			e.stopPropagation();
			var event : NBEvent;
			if(e.currentTarget == forwardBtn) {
				event = new NBEvent(NBEvent.TRANSITION_FORWARD, true); 
			} else {
				event = new NBEvent(NBEvent.TRANSITION_BACKWARD, true); 
			}
			dispatchEvent(event);
		}
	}
}
